# -*- codeing = utf-8 -*-
# @Time : 2022/8/31 20:03
# @Author : ZN
# @Email : 747723508@qq.com
# @File : serializers.py
# @Software: PyCharm
from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from .models import *


class LabelSerializer(ModelSerializer):
    username = serializers.CharField(source='user.username', read_only=True)

    class Meta:
        model = Label
        fields = '__all__'
        extra_kwargs = {
            'user': {'required': False, 'write_only': True}
        }


class TopicSerializer(ModelSerializer):
    label_name = serializers.CharField(source='label.name', read_only=True)
    user_name = serializers.CharField(source='user.username', read_only=True)

    class Meta:
        model = Topic
        exclude = ['is_delete']


class TopicStudentSerializer(ModelSerializer):
    label_name = serializers.CharField(source='label.name', read_only=True)
    user_name = serializers.CharField(source='user.username', read_only=True)

    class Meta:
        model = Topic
        exclude = ['is_delete', 'answer']
